package com.iknow.activity;

import android.app.Activity;
import android.app.ProgressDialog;
import android.app.TabActivity;
import android.content.ComponentName;
import android.content.Intent;
import android.content.ServiceConnection;
import android.os.Bundle;
import android.os.IBinder;
import android.view.View;
import android.view.View.OnClickListener;
import android.widget.Button;
import android.widget.ImageView;
import android.widget.RelativeLayout;
import android.widget.TabHost;
import android.widget.TabHost.TabSpec;
import android.widget.Toast;
import com.iknow.IKnow;
import com.iknow.image.ImageManager;
import com.iknow.image.ProfileImageCacheManager;
import com.iknow.task.CommonTask.BingSessionTask;
import com.iknow.task.GenericTask;
import com.iknow.task.TaskAdapter;
import com.iknow.task.TaskListener;
import com.iknow.task.TaskParams;
import com.iknow.task.TaskResult;
import com.iknow.util.Loger;
import com.iknow.xmpp.service.aidl.IXmppFacade;
import com.iknow.xmpp.service.aidl.IXmppFacade.Stub;
import com.xmpp.task.LoginAsyncTask;

public class IKnowActivity extends TabActivity
{
  private static final Intent SERVICE_INTENT = new Intent("MAIN_UI_STARTED");
  private View.OnClickListener FollowButtonClickListener;
  private View.OnClickListener IKNowClickListener;
  private View.OnClickListener QingboButtonClickListener;
  private final String TAG = "IKnowActivity";
  private boolean mBinded;
  private RelativeLayout mFollowButton;
  private Intent mHomeIntent;
  private TabHost mHost;
  private RelativeLayout mIKnowButton;
  private Intent mMyIKnowIntent;
  private ProgressDialog mProgressDialog;
  private Button mQingboButton;
  private Intent mQingboIntent;
  private final ServiceConnection mServConn;
  private CommonTask.BingSessionTask mSessionTask;
  private LoginAsyncTask mTask;
  private TaskListener mTaskListener;
  private IXmppFacade mXmppFacade;
  private ImageView view_follow;
  private ImageView view_myiknow;

  static
  {
    SERVICE_INTENT.setComponent(new ComponentName("com.iknow", "com.iknow.xmpp.service.IKnowXmppService"));
  }

  public IKnowActivity()
  {
    this.mServConn = new LoginServiceConnection(this, null);
    this.FollowButtonClickListener = new View.OnClickListener(this)
    {
      public void onClick()
      {
        IKnowActivity.access$0(this.this$0).setCurrentTab(0);
        IKnowActivity.access$1(this.this$0);
        IKnowActivity.access$2(this.this$0).setBackgroundResource(2130837592);
      }
    };
    this.QingboButtonClickListener = new View.OnClickListener(this)
    {
      public void onClick()
      {
        IKnowActivity.access$0(this.this$0).setCurrentTab(1);
        IKnowActivity.access$1(this.this$0);
        IKnowActivity.access$3(this.this$0).setBackgroundResource(2130837595);
      }
    };
    this.IKNowClickListener = new View.OnClickListener(this)
    {
      public void onClick()
      {
        IKnowActivity.access$0(this.this$0).setCurrentTab(2);
        IKnowActivity.access$1(this.this$0);
        IKnowActivity.access$4(this.this$0).setBackgroundResource(2130837593);
      }
    };
    this.mTaskListener = new TaskAdapter(this)
    {
      public String getName()
      {
        return null;
      }

      public void onPostExecute(, TaskResult paramTaskResult)
      {
        if (paramGenericTask instanceof LoginAsyncTask)
        {
          if (paramTaskResult != TaskResult.OK)
            break label88;
          this.this$0.startService(IKnowActivity.access$5());
          IKnowActivity.access$6(this.this$0);
          if (IKnowActivity.access$8(this.this$0) != null)
            IKnowActivity.access$8(this.this$0).dismiss();
        }
        if (paramGenericTask instanceof CommonTask.BingSessionTask)
        {
          if (paramTaskResult != TaskResult.OK)
            break label118;
          ((IKnow)this.this$0.getApplication()).setSessionBinded(true);
          Loger.i("IKnowActivity", "bind session OK");
        }
        while (true)
        {
          while (true)
          {
            return;
            label88: Toast.makeText(this.this$0.getCurrentActivity().getParent(), IKnowActivity.access$7(this.this$0).getErrorMessage(), 0).show();
          }
          label118: Loger.e("IKnowActivity", "bind session error");
        }
      }

      public void onPreExecute()
      {
        paramGenericTask instanceof LoginAsyncTask;
      }
    };
  }

  private void bindSession()
  {
    if (((IKnow)getApplication()).isSessionBinded());
    while (true)
    {
      return;
      TaskParams localTaskParams = new TaskParams();
      localTaskParams.put("xmpp", this.mXmppFacade);
      this.mSessionTask = new CommonTask.BingSessionTask();
      this.mSessionTask.setListener(this.mTaskListener);
      CommonTask.BingSessionTask localBingSessionTask = this.mSessionTask;
      TaskParams[] arrayOfTaskParams = new TaskParams[1];
      arrayOfTaskParams[0] = localTaskParams;
      localBingSessionTask.execute(arrayOfTaskParams);
    }
  }

  private void initIntents()
  {
    this.mHomeIntent = new Intent(this, HomeActivity.class);
    this.mQingboIntent = new Intent(this, ChoseBolgActivity.class);
    this.mMyIKnowIntent = new Intent(this, MyIKnowActivity.class);
  }

  private void initTab()
  {
    TabHost.TabSpec localTabSpec1 = this.mHost.newTabSpec("home");
    localTabSpec1.setContent(this.mHomeIntent);
    localTabSpec1.setIndicator("home");
    this.mHost.addTab(localTabSpec1);
    TabHost.TabSpec localTabSpec2 = this.mHost.newTabSpec("qingbo");
    localTabSpec2.setContent(this.mQingboIntent);
    localTabSpec2.setIndicator("qingbo");
    this.mHost.addTab(localTabSpec2);
    TabHost.TabSpec localTabSpec3 = this.mHost.newTabSpec("myiknow");
    localTabSpec3.setContent(this.mMyIKnowIntent);
    localTabSpec3.setIndicator("myiknow");
    this.mHost.addTab(localTabSpec3);
    this.view_follow.setBackgroundResource(2130837592);
  }

  private void initUI()
  {
    this.mFollowButton = ((RelativeLayout)findViewById(2131296352));
    this.view_follow = ((ImageView)findViewById(2131296353));
    this.mFollowButton.setOnClickListener(this.FollowButtonClickListener);
    this.mQingboButton = ((Button)findViewById(2131296356));
    this.mQingboButton.setOnClickListener(this.QingboButtonClickListener);
    this.mIKnowButton = ((RelativeLayout)findViewById(2131296354));
    this.view_myiknow = ((ImageView)findViewById(2131296355));
    this.mIKnowButton.setOnClickListener(this.IKNowClickListener);
  }

  private void resetButtonBackground()
  {
    this.view_follow.setBackgroundResource(2130837591);
    this.mQingboButton.setBackgroundResource(2130837596);
    this.view_myiknow.setBackgroundResource(2130837594);
  }

  protected void onActivityResult(int paramInt1, int paramInt2, Intent paramIntent)
  {
    Loger.d("MyIKnowActivity", "onActivityResult");
  }

  protected void onCreate(Bundle paramBundle)
  {
    super.onCreate(paramBundle);
    requestWindowFeature(1);
    setContentView(2130903065);
    this.mHost = getTabHost();
    initIntents();
    initUI();
    initTab();
  }

  protected void onDestroy()
  {
    IKnow.mProfileImageCacheManager.getImageManager().clear();
    super.onDestroy();
  }

  protected void onPause()
  {
    if (this.mBinded)
    {
      unbindService(this.mServConn);
      this.mBinded = false;
    }
    this.mXmppFacade = null;
    super.onPause();
  }

  protected void onResume()
  {
    super.onResume();
  }

  private class LoginServiceConnection
  implements ServiceConnection
  {
    public void onServiceConnected(, IBinder paramIBinder)
    {
      IKnowActivity.access$9(this.this$0, IXmppFacade.Stub.asInterface(paramIBinder));
    }

    public void onServiceDisconnected()
    {
      IKnowActivity.access$9(this.this$0, null);
    }
  }
}